<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/reception/detail/style/css/index.css" />
	<script type="text/javascript" src="${pageContext.request.contextPath }/backstage/detail/style/js/jquery.js"></script>
	<script type="text/javascript">
		 // 删除菜品项
		function removeSorder(node) {
			var id = node.lang;
			if(confirm("您确定要删除这条数据") == true){ 
				$.ajax({
					url:"${pageContext.request.contextPath}/cart/removeCart.do",
					type:"GET",
					data:{'id':id},
					dataType:"text",
					success:function(data) {
						if(data == "success") {
							$(node).parent().parent().remove();
							alert("删除成功！");
						}
						var totalPrice = 0;
						$(".price").each(function() {
							totalPrice +=  parseInt($(this).text());
						});
						$("#total").text(totalPrice);
						
					},
					error:function() {
						alert("服务器错误");
					}
				});
			} 
		
		}
	
		/* $(function(){
			var totalPrice = 0;
			$(".price").each(function() {
				totalPrice +=  parseInt($(this).text());
			});
			$("#total").text(totalPrice);
		}); */
		
		// 修改菜品项数量
		function alterSorder(node) {
			var snumber = node.value;
			var id = node.lang;
			$.ajax({
				url:"mudifyNum.do",
				type:"GET",
				data:{'num':snumber, 'id':id},
				dataType:"text",
				success:function(data) {
					alert("数量修改成功");
					$(node).parent().next().next().text(data);
					var totalPrice = 0;
					$(".price").each(function() {
						totalPrice +=  parseInt($(this).text());
					});
					$("#total").text(totalPrice);
					
				},
				error:function() {
					alert("服务器错误");
				}
			});
			
			
		}
		
		function genernateOrder() {
			window.location.href="${pageContext.request.contextPath}/Orders/placeAnOrder.do";
		} 
		// 下单
/* 		function genernateOrder() {
			$.ajax({
				url:"${pageContext.request.contextPath}/Orders/placeAnOrder.do",
				type:"GET",
				dataType:"text",
				success:function(data) {
					if(data == "ok"){
						alert("下单成功");
						window.location.href = "${pageContext.request.contextPath}/reception/detail/clientOrderList.jsp";	
					}
					else if(data == "toLogin"){
						alert("请先登录");
						window.location.href = "${pageContext.request.contextPath}/login/login.jsp";
					}else {
						alert("下单失败");
					}
									
				},
				error:function() {
					alert("服务器错误");
				}
			});
			
		}  */
	</script>
</head>

<body style="text-align: center">
	<div id="all">
		<div id="menu">
			<!-- 餐车div -->
			<div id="count">
				<table align="center" width="100%">
					<tr height="40">
				 		<td align="center" width="20%">菜名</td>
				 		<td align="center" width="20%">单价</td>
				 		<td align="center" width="20%">数量</td>
				 		<td align="center" width="20%">桌子</td>
				 		<td align="center" width="20%">小计</td>
				 		<td align="center" width="20%">操作</td>
				 	</tr>
				 	<c:forEach items="${cart.cartItems }" var="foodList">
						<tr height="60">
					 		<td align="center" width="20%">${foodList.food.foodname }</td>
					 		<td align="center" width="20%">￥${foodList.food.price }</td>
					 		<td align="center" width="20%">
					 			<input type="text" value="${foodList.foodCount }" size="3" lang="${foodList.food.id }" onblur="alterSorder(this)"/>
					 		</td>
					 		<td align="center" width="20%">
					 			<select id="select" name="dinnerTable.id">
					 				<c:forEach items="${dinnertables }" var="dinnertableList">
					 					<option value="${dinnertableList.id }">${dinnertableList.tablename }</option>
					 				</c:forEach>
					 			</select>
					 		</td>
					 		<td align="center" width="20%" class="price">${foodList.subtotal }</td>
					 		<td align="center" width="20%">
					 			<input type="button" value="删除" class="btn_next" lang="${foodList.food.id }" onclick="removeSorder(this)" />
					 		</td>
					 	</tr>
					</c:forEach>
					<tr>
						<td colspan="6" align="right">总计:
							<span style="font-size:36px;">&yen;&nbsp;<span id="total">${cart.total }</span></span>
							<label
								id="counter" style="font-size:36px"></label>
						</td>
					</tr>
					<tr>
						<td>
							<input type="button" value="清空购物车" class="btn_next" onclick="genernateOrder()" />
						</td>
						<td colspan="6" style="margin-left: 100px; text-align: center;"align="right">
							<input type="hidden" name="bId" value="">
							<input type="button" value="下单" class="btn_next" onclick="genernateOrder()" />
						</td>
					</tr>
				</table>
			</div>
		</div>

		<!-- 右边菜系列表，菜品搜索框  -->
		<div id="dish_class">
			<div id="dish_top">
				<ul>
				<li class="dish_num"></li>
					<li>
						<a href="clientOrderList.jsp">
							<img src="${pageContext.request.contextPath }/reception/detail/style/images/call2.gif" />
						</a>
					</li>
				</ul>
			</div>

			<div id="dish_2">
				<ul>
					
						<li>
							<a href="caidan.jsp">粤菜</a>
						</li>
					
						<li>
							<a href="chuancai.jsp">川菜</a>
						</li>
					
						<li>
							<a href="chuancai.jsp">湘菜</a>
						</li>
					
						<li>
							<a href="chuancai.jsp">东北菜</a>
						</li>
					
				</ul>
			</div>
			<div id="dish_3">
				<!-- 搜索菜品表单  -->
				<form action="#" method="post">
					<table width="166px">
						<tr>
							<td>
								<input type="text" id="dish_name" name="foodName" class="select_value" /> 
								<input type="hidden" value="selectFood" name="method">
							</td>
						</tr>
						<tr>
							<td><input type="submit" id="sub" value="" /></td>
						</tr>
						<tr>
							<td>
								<a href="#">
									<img src="${pageContext.request.contextPath }/reception/detail/style/images/look.gif" />
								</a>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>
</body>
</html>
